package com.jinmdz.fmis.generator.util;

import com.jinmdz.fmis.common.ext.ArrayListExt;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;

/**
 * Generator 类型转化工具类
 *
 * @author LiCongLu
 * @date 2019-12-16 10:57
 */
public class GeneratorUtil {

    /**
     * 得到,jdbcType=字符串
     *
     * @param dataType
     * @return
     */
    public static String getJdbcType(String dataType) {
        String jdbcType = ",jdbcType=";
        switch (dataType) {
            case "int":
                jdbcType += "INTEGER";
                break;
            case "varchar":
                jdbcType += "VARCHAR";
                break;
            case "tinyint":
                jdbcType += "TINYINT";
                break;
            case "smallint":
                jdbcType += "SMALLINT";
                break;
            case "decimal":
                jdbcType += "DECIMAL";
                break;
            case "bigint":
                jdbcType += "BIGINT";
                break;
            case "double":
                jdbcType += "DOUBLE";
                break;
            case "float":
                jdbcType += "FLOAT";
                break;
            case "numeric":
                jdbcType += "NUMERIC";
                break;
            case "date":
                jdbcType += "DATE";
                break;
            case "datetime":
                jdbcType += "TIMESTAMP";
                break;
            default:
                jdbcType = "";
                break;
        }
        return jdbcType;
    }

    /**
     * 得到JavaType
     *
     * @param dataType
     * @return
     */
    public static String getJavaType(String dataType) {
        String javaType;
        switch (dataType) {
            case "int":
                javaType = Integer.class.getSimpleName();
                break;
            case "varchar":
                javaType = String.class.getSimpleName();
                break;
            case "tinyint":
                javaType = Integer.class.getSimpleName();
                break;
            case "smallint":
                javaType = Integer.class.getSimpleName();
                break;
            case "decimal":
                javaType = BigDecimal.class.getSimpleName();
                break;
            case "bigint":
                javaType = Long.class.getSimpleName();
                break;
            case "double":
                javaType = Double.class.getSimpleName();
                break;
            case "float":
                javaType = Float.class.getSimpleName();
                break;
            case "numeric":
                javaType = BigDecimal.class.getSimpleName();
                break;
            case "date":
                javaType = Date.class.getSimpleName();
                break;
            case "datetime":
                javaType = Date.class.getSimpleName();
                break;
            default:
                javaType = String.class.getSimpleName();
                break;
        }
        return javaType;
    }

    /**
     * 得到JavaType的class
     *
     * @param dataType
     * @return
     */
    public static Class getJavaTypeClass(String dataType) {
        Class javaType;
        switch (dataType) {
            case "int":
                javaType = Integer.class;
                break;
            case "varchar":
                javaType = String.class;
                break;
            case "tinyint":
                javaType = Integer.class;
                break;
            case "smallint":
                javaType = Integer.class;
                break;
            case "decimal":
                javaType = BigDecimal.class;
                break;
            case "bigint":
                javaType = Long.class;
                break;
            case "double":
                javaType = Double.class;
                break;
            case "float":
                javaType = Float.class;
                break;
            case "numeric":
                javaType = BigDecimal.class;
                break;
            case "date":
                javaType = Date.class;
                break;
            case "datetime":
                javaType = Date.class;
                break;
            default:
                javaType = String.class;
                break;
        }
        return javaType;
    }

    /**
     * 忽略字段
     *
     * @return
     */
    public static ArrayList<String> getIgnoreCamelName() {
        ArrayListExt<String> listExt = new ArrayListExt<>();
        listExt.addExt("id", "deleted", "funeralParlourCode", "createUserId", "gmtCreate", "unmodified", "modifiedUserId", "gmtModified", "version");
        return listExt;
    }
}
